package main;

import java.io.File;
import java.io.IOException;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

public class Config {
	
	private boolean Mysql_enabled;
	private boolean JoinLisener_enabled;
	private boolean Rewrite;
	private boolean Vote;
	
	public void CreateConfig(){
		
		File file = new File("plugins/Projekt", "config.yml");
		FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
		String moduls = "LoadModule.";
		if (!file.exists()){
			cfg.addDefault(moduls + "MySQL", true);
			cfg.addDefault(moduls + "PlayerLisener", true);
			cfg.addDefault(moduls + "Voter", true);
			cfg.addDefault("Reset." + "Config", false);
			
			String db = "database.";
			cfg.addDefault(db + "host", "localhost");
			cfg.addDefault(db + "port", 3306);
			cfg.addDefault(db + "user", "root");
			cfg.addDefault(db + "password", "password");
			cfg.addDefault(db + "database", "database");
			cfg.options().copyDefaults(true);
			try {
				cfg.save(file);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		this.Mysql_enabled = cfg.getBoolean(moduls + "MySQL", true);
		this.JoinLisener_enabled = cfg.getBoolean(moduls + "PlayerLisener", true);
		this.Rewrite = cfg.getBoolean("Reset.Config");
		this.Vote = cfg.getBoolean(moduls + "Voter");
	}
	
	public boolean RewriteConfig(String version){
		File file = new File("plugins/Projekt", "config.yml");
		if (file.delete()){
			CreateConfig();
			return true;
		}else{
			System.err.println(" Could not reset Config, loading old one (Maybe no permissions?)");
		}
		return false;
		
	}
	
	//Sets aus der sicht anderer datein :D
	public boolean setMysql(){
		return this.Mysql_enabled;
	}
	
	public boolean setJoinLisener(){
		return this.JoinLisener_enabled;
	}
	public boolean setRewrite(){
		return this.Rewrite;
	}
	public boolean setVote(){
		return this.Vote;
	}
}
